/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.feiyue.basic.server.parser;

import android.util.Xml;
import com.feiyue.helper.Helper;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class Xml2ParseBookList {
	private List<Book> BookList = new ArrayList();
	private int categoryId;

	public Xml2ParseBookList(String paramString, int paramInt)
			throws XmlPullParserException, IOException {
		this.categoryId = paramInt;
		XmlPullParser localXmlPullParser = Xml.newPullParser();
		localXmlPullParser.setInput(
				new ByteArrayInputStream(paramString.getBytes()), null);
		Parser(localXmlPullParser);
	}

	private void Parser(XmlPullParser paramXmlPullParser)
    throws IOException, XmlPullParserException
  {
    Book localBook = null;
    
    int eventType = paramXmlPullParser.getEventType();
    
    while (eventType != XmlPullParser.END_DOCUMENT) {
    	if (eventType == XmlPullParser.START_DOCUMENT) {
    		//start parser
    	} else if (eventType== XmlPullParser.START_TAG) {
    		String tagName = paramXmlPullParser.getName();
    		
    		if ("booklist".equals(tagName)) {
    		} else if ("book".equals(tagName)) {
    			localBook = new Book();
    	       localBook.setCategoryId(this.categoryId);
    		} else if ("id".equals(tagName)) {
    			paramXmlPullParser.next();
    	        localBook.setId(Integer.valueOf(paramXmlPullParser.getText()).intValue());
    		} else if ("name".equals(tagName)) {
    			paramXmlPullParser.next();
    	        localBook.setName(Base64.decode(paramXmlPullParser.getText(), "utf-8"));
    		} else if ("author".equals(tagName)) {
    			paramXmlPullParser.next();
    	        localBook.setAuthor(Base64.decode(paramXmlPullParser.getText(), "utf-8"));
    		} else if ("issuestate".equals(tagName)) {
    			paramXmlPullParser.next();
    		      if ((paramXmlPullParser.getText() != null) && (!(paramXmlPullParser.getText().equals("null"))))
    		        localBook.setIssuestate(Base64.decode(paramXmlPullParser.getText(), "utf-8"));
    		      localBook.setIssuestate("全本");
    		} else if ("introduction".equals(tagName)) {
    			paramXmlPullParser.next();
    	        localBook.setIntroduction(Base64.decode(paramXmlPullParser.getText(), "utf-8"));
    		} else if ("coveraddr".equals(tagName)) {
    			paramXmlPullParser.next();
    	        localBook.setCoverAddr(Base64.decode(paramXmlPullParser.getText(), "utf-8"));
    		}
    	} else if (eventType== XmlPullParser.END_TAG) {
    		String tagName = paramXmlPullParser.getName();
    		
    		if ("booklist".equals(tagName)) {
    		} else if ("book".equals(tagName)) {
    			localBook.setCoverid(Helper.getRandomCover_index());
    	        this.BookList.add(localBook);
    		} else if ("id".equals(tagName)) {
    		} else if ("name".equals(tagName)) {
    		} else if ("author".equals(tagName)) {
    		} else if ("issuestate".equals(tagName)) {
    		} else if ("introduction".equals(tagName)) {
    		} else if ("coveraddr".equals(tagName)) {
    		}
    	}
    	eventType = paramXmlPullParser.next();
    }
  }

	public List<Book> getBookList() {
		return this.BookList;
	}

	public void setBookList(List<Book> paramList) {
		this.BookList = paramList;
	}
}